import { jiadesocket } from './server';
export function jiadesocketio() {
  let socketver = jiadesocket();
  function createWsServer() {}
  function getMixinWs(customSocketFunction?: Function) {
    socketver.onopen = () => {
      createWsServer();
    };
    socketver.onmessage = (event) => {
      if (event && event.data !== '连接成功') {
        try {
          const message = JSON.parse(event.data);
          if (customSocketFunction) {
            customSocketFunction(message);
          }
        } catch (error) {}
      }
    };
    socketver.onerror = (error) => {
      console.error('WebSocket error:', error);
      // 处理错误
    };
    socketver.onclose = () => {
      socketver = jiadesocket();
      getMixinWs();
      // 处理连接关闭
    };
  }
  return {
    socketver,
    getMixinWs,
  };
}
